package com.xiyuan.task;

import com.xiyuan.mapper.MemoEventMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class MemoOverTime {
    private final TaskScheduler taskScheduler;
    private final MemoEventMapper memoEventMapper;

    @Autowired
    public MemoOverTime(TaskScheduler taskScheduler,MemoEventMapper memoEventMapper) {
        this.taskScheduler = taskScheduler;
        this.memoEventMapper = memoEventMapper;
    }

    /**
     * 每两分钟执行一次
     */
    @Scheduled(cron = "0 0/2 * * * ?")
    public void updateOverTime(){
        log.info("定时任务执行中...");
        executeTask();
    }

    private void executeTask() {
        doSomethingImportant();
    }

    private void doSomethingImportant() {
        // 更新过期事件
       memoEventMapper.updateOverTime();
    }
}
